local skel = fk.CreateSkill {
  name = "emo__lehuo",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__lehuo"] = "乐祸",
  [":emo__lehuo"] = "锁定技，每当一名角色进入濒死状态时，若其体力值小于0，你增加一点体力上限；若其本轮未进入回合，你获得一张黑色锦囊牌。",

  ["$emo__lehuo1"] = "好戏才刚刚开始。",
}

skel:addEffect(fk.EnterDying, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) then
      local choices = {}
      if #player.room.logic:getEventsOfScope(GameEvent.Turn, 1, function (e) return e.data.who == target end, Player.HistoryRound) == 0 then
        table.insert(choices, "trick")
      end
      if target.hp < 0 then
        table.insert(choices, "maxHp")
      end
      if #choices > 0 then
        event:setCostData(self, choices)
        return true
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local choices = event:getCostData(self)
    if table.contains(choices, "maxHp") then
      room:changeMaxHp(player, 1)
      if player.dead then return end
    end
    if table.contains(choices, "trick") then
      local ids = room:getCardsFromPileByRule(".|.|club,spade|.|.|trick", 1, "allPiles")
      if #ids > 0 then
        room:moveCardTo(ids, Player.Hand, player, fk.ReasonJustMove, skel.name, nil, false, player)
      end
    end
  end,
})

return skel
